﻿using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Script.Serialization;

namespace Sc.Web.Controllers.WebApi
{
    public class CarInfoApiController : ApiController
    {
        /// <summary>
        /// 车辆服务层
        /// </summary>
        private readonly CarInfoService service = new CarInfoService();
        /// <summary>
        /// 获取车辆
        /// </summary>
        /// <param name="orgzNo">机构Id</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <returns></returns>
        [HttpPost]
        public object GetPageData()
        {
            int orgzNo = Convert.ToInt32(HttpContext.Current.Request["orgzNo"]);
            int pageSize = Convert.ToInt32(HttpContext.Current.Request["pageSize"]);
            int pageIndex = Convert.ToInt32(HttpContext.Current.Request["pageIndex"]);
            JavaScriptSerializer json = new JavaScriptSerializer();
            var tmp = service.GetList(orgzNo, pageSize, pageIndex);
            var data = json.Serialize(tmp);
            if (tmp == null)
            {
                data = "[]";
            }
            return new HttpResponseMessage { Content = new StringContent(data, System.Text.Encoding.UTF8, "application/json") };
        }
        /// <summary>
        /// 更新车辆状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object UpdateState()
        {
            int carNo = Convert.ToInt32(HttpContext.Current.Request["carNo"]);
            int carState = Convert.ToInt32(HttpContext.Current.Request["carState"]);
            return new CarInfoService().UpdateCarState(carNo, carState);
        }
    }
}
